//
//  YuYueDetailFooterView.m
//  FD
//
//  Created by xiaofang wang on 2019/2/12.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//
//这个一个tableView(头:145 + cell:50*5 + 尾:60)
#import "YuYueDetailFooterView.h"
//复用
//model
#import "WSOrderMsgModel.h"
//view
#import "OrderFooterTopCouponFreightView.h" //头
#import "OrderFooterCenterTableViewCell.h"
//代理封装
#import "OrderFooterCenterTableViewProxy.h"



#import "YuYueDetailFooterViewFooterView.h"

@interface YuYueDetailFooterView()
/**tableView*/
@property (nonatomic, strong) UITableView *tableView;
/**tableViewProxy*/
@property (nonatomic, strong) OrderFooterCenterTableViewProxy *proxy;
/**头:优惠券、配送费、已优惠 45*3+10=145*/
@property (nonatomic, strong) OrderFooterTopCouponFreightView *headerView;
/**尾:按钮以及交互*/
@property (nonatomic, strong) YuYueDetailFooterViewFooterView *footerView;

@end

@implementation YuYueDetailFooterView
#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.tableView.frame = self.bounds;
    [self addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView; //头
    self.tableView.tableFooterView = self.footerView; //尾
    
//    {
//        //设置假数据
//        self.proxy.dataArr = [self fakeData];
//        [self.headerView setDataWithCoupon:@5 freight:@4 alreadCoupon:0.0 sum:@888];
//        [self.footerView placeBtnAndHandleInteractionWithStatus:@(4)];
//    }
}

#pragma mark- 接口
//更新头部信息数据
- (void)updateYuYueDetailFooterViewHeaderWithCoupon:(NSNumber *)coupon freight:(NSNumber *)freight alreadyCoupon:(CGFloat)alreayCoupon sumPrice:(NSNumber *)sum {
    [self.headerView setDataWithCoupon:coupon freight:freight alreadCoupon:alreayCoupon sum:sum];
}

//更新cell内容
- (void)updateYuYueDetailFooterViewWithDataArray:(NSArray *)array {
    self.proxy.dataArr = array;
   
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    });
}

//更新底部内容
- (void)updateYuYueDetailFooterViewFooterWithStatus:(NSNumber *)status paytype:(nonnull NSNumber *)paytype{
    [self.footerView placeBtnAndHandleInteractionWithStatus:status paytype:paytype];
}


#pragma mark - getter
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        
        _tableView.scrollEnabled = NO; //禁止滚动
        
        //代理
        _tableView.delegate = self.proxy;
        _tableView.dataSource = self.proxy;
        
        //注册cell
        [_tableView registerNib:[UINib nibWithNibName:@"OrderFooterCenterTableViewCell" bundle:nil] forCellReuseIdentifier:@"OrderFooterCenterTableViewCell"];
        
        //取消分割线
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    }
    return _tableView;
}

- (OrderFooterCenterTableViewProxy *)proxy {
    if (!_proxy) {
        _proxy = [[OrderFooterCenterTableViewProxy alloc] init];
    }
    return _proxy;
}
- (OrderFooterTopCouponFreightView *)headerView {
    if (!_headerView) {
        _headerView = [[OrderFooterTopCouponFreightView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 145)];
    }
    return _headerView;
}
- (YuYueDetailFooterViewFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[YuYueDetailFooterViewFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
        
        FDWeakSelf;
        //block事件回调
        _footerView.clickLeftBtnBlock = ^{
            if ([weakSelf.delegate respondsToSelector:@selector(clickYuYueDetailFooterBtnActionType:)]) {
                [weakSelf.delegate clickYuYueDetailFooterBtnActionType:(YuYueDetailFooterViewActionLeft)];
            }
        };
        _footerView.clickRightBtnBlock = ^{
            if ([weakSelf.delegate respondsToSelector:@selector(clickYuYueDetailFooterBtnActionType:)]) {
                [weakSelf.delegate clickYuYueDetailFooterBtnActionType:(YuYueDetailFooterViewActionRight)];
            }
        };
    }
    return _footerView;
}

//- (NSArray *)fakeData {
//    NSArray *fakeArr = @[@{@"title":@"订单信息",@"content":@""},
//                         @{@"title":@"姓名:",@"content":@"刘德华"},
//                         @{@"title":@"联系电话:",@"content":@"1008611"},
//                         @{@"title":@"地址:",@"content":@"3 Kenley ava"},
//                         @{@"title":@"备注:",@"content":@""},
//                         ];
//
//    //转模型
//    NSMutableArray *tempArrM = @[].mutableCopy;
//    for (NSDictionary *dic  in fakeArr) {
//        WSOrderMsgModel *model = [WSOrderMsgModel mj_objectWithKeyValues:dic];
//        [tempArrM addObject:model];
//    }
//
//    return [tempArrM copy];
//}



@end
